﻿FlyTalk.views.MyTalkActivityView = Ext.extend(Ext.Panel, {
	id: 'MyTalkActivityView',
	title: "My Activity",
	layout: 'card', 
			
    initComponent: function () {

        this.searchButton = new Ext.Button({
            iconCls: 'search',
			iconMask: true,
            handler: this.onSearch,
            scope: this
        });
		
		this.composeButton = new Ext.Button({
            iconCls: 'compose',
			iconMask: true,
            handler: this.onCompose,
            scope: this
        });
		
		this.homeButton = new Ext.Button({
            iconCls: 'home',
			iconMask: true,
            handler: this.onHome,
            scope: this
        });
		
			// Tweet toolbar
		this.myTalkActivityToolbar = new Ext.Toolbar({
			id: 'tweetToolbar',
			title: 'MyTalkActivityView',
			dock: 'top',
			layout: 'hbox',
			items: [
				this.homeButton,
				{xtype: 'spacer'},
				this.searchButton,
				this.composeButton,
			]
		});
		

        this.dockedItems = [this.myTalkActivityToolbar];

		// post store
		// not in PostStore.js because not sure how to instantiate a specific store in that class
		this.PostStore = new Ext.data.JsonStore({
			model : 'PostModel',
			autoLoad: true,

			proxy: {
          		type: 'scripttag',
          		url: 'http://search.twitter.com/search.json',
          		extraParams: {
             		q: 'Air',
                	rpp: 6,
                	//suppress_response_codes: true
          		},
          		reader: {
                	type: 'json',
                	root: 'results'
         		}
    		},
			
		});

		
		this.tweetList = new Ext.List({
			fullscreen: true,
			//scroll: false,
			disableSelection: true,
			grouped: false,
			
			grouped : false,
			indexBar: false,
			//onItemDisclosure: true,
			store: this.PostStore,
		
			emptyText: '<div style="margin:5px;">No tweets cached.</div>',
			itemTpl : [ 
				//'<div id="tweet_container">',
                   '<tpl for=".">',
                        '<div class="tweet_data">',
                        	'<div class="tweet_avatar">',
                            	'<img width="30" height="30" src="{profile_image_url}"/>',
                       		'</div>',
                        	'<div class="tweet_content">',
                            	'<a class="user" href="http://twitter.com/{from_user}">{from_user}</a>&nbsp;',
                            	'{text}',
                       	 	'</div>',
                        	'<div class="clear"></div>',
                        '</div>',
                   '</tpl>',
                //'</div>'
			],
		
					
			listeners:{
				itemTap: function(dv, index, tweet, evt){
					//alert(this.store.getAt(index));
					//Ext.Msg.alert('List Option Tapped');
					//FlyTalk.views.MyTalkActivityView.onTweet(this.store.getAt(index).data);				
				},			
			},
			
			onItemDisclosure: {
				handler: this.onDisclosure,
			}
				

			

		});
	
	
		this.items = [this.tweetList];
		
		FlyTalk.views.MyTalkActivityView.superclass.initComponent.call(this);


        
    },

    onSearch: function () {
        Ext.dispatch({
            controller: FlyTalk.controllers.ftController,
            action: 'openSearch'
        });
    },

    onCompose: function (record, index) {
        Ext.dispatch({
            controller: FlyTalk.controllers.ftController,
            action: 'openCompose',
        //    note: record
        });
    },
	
	 onTweet: function (tweet) {
        Ext.dispatch({
            controller: FlyTalk.controllers.ftController,
            action: 'openThread',
            post: tweet,
        });
    },

	onDisclosure: function(data){
		//Ext.Msg.alert('List Option method working!');
		
		var overlay2 = new Flytalk.views.overlay();
		overlay2.show();
		
		
		var overlay = new Ext.Panel({
			floating: true,
			modal: true,
			centered: true,
			width: Ext.platform.isPhone ? 260 : 400,
			height: Ext.platform.isPhone ? 220 : 400,
			styleHtmlContent: true,
			dockedItems: overlayTb,
			scroll: 'vertical',
		});
		
		var overlay2 = new Flytalk.views.overlay();
		overlay2.show();
		
		overlay.show();
	},
	
	onHome: function () {
        Ext.dispatch({
            controller: FlyTalk.controllers.ftController,
            action: 'index',            
        });
    },
	
	onHome: function () {
        Ext.dispatch({
            controller: FlyTalk.controllers.ftController,
            action: 'index',            
        });
    },
/*
    refreshColumn: function () {
        this.notesList.refresh();
    }*/
});